import { SecTimer } from "../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../com/gengine/core/frame/TimerType";
import { HTMLUtil } from "../../../com/gengine/utils/HTMLUtil";
import { GTextFormat } from "../../common/GTextFormat";
import { FontUtil } from "../../common/font/FontUtil";
import { FilterConst } from "../../component/gconst/FilterConst";
import { LayerManager } from "./LayerManager";
import { Global } from "../../../com/gengine/global/Global";
type int = number;
//class MsgCopyTaskEndImpl
    
    export  class MsgCopyTaskEndImpl
    {
        

        /* internal  */stopTimer(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
                this._timer.isDelete = false;
            }
            return;
        }

        /* internal  */startTimer(): void
        {
            if (this._timer) 
            {
                this._timer.delay = this._daily;
                this._timer.repeatCount = this._count * this._daily;
            }
            else 
            {
                this._timer = new SecTimer(this._daily, this._count * this._daily);
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
                this._timer.addListener(TimerType.COMPLETE, this.onTimerComHandler);
            }
            if (!this._timer.running) 
            {
                this._timer.start();
            }
            return;
        }

        /* internal  */onTimerHandler(arg1: SecTimer): void
        {
            var loc1;
            var loc2=((loc1 = this)._currentCount - 1);
            loc1._currentCount = loc2;
            this.setText();
            return;
        }

        /* internal  */onTimerComHandler(arg1: SecTimer): void
        {
            if (this._callBack != null) 
            {
                this._callBack();
            }
            this.hide();
            return;
        }

        /* internal  */setText(): void
        {
            var loc1=this._str.split("n");
            var loc2="#66FF33";
            if (this._currentCount >= this._count * 2 / 3) 
            {
                loc2 = "#66FF33";
            }
            else if (this._currentCount <= this._count / 3) 
            {
                loc2 = "#FF0000";
            }
            else 
            {
                loc2 = "#E46C0A";
            }
            this._wordTxt.htmlText = HTMLUtil.addColor(loc1[0] + HTMLUtil.addColor(this._currentCount.toString(), loc2) + loc1[1], "#ffc000");
            return;
        }

        public show(arg1: string, arg2: int, arg3: int, arg4: Function=null): void
        {
            this._str = arg1;
            this._daily = arg2;
            this._count = arg3;
            this._currentCount = arg3;
            this._callBack = arg4;
            this.stopTimer();
            if (!this._wordTxt) 
            {
                this._wordTxt = new Object /* flash.text.TextField */();
                this._wordTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
                this._wordTxt.defaultTextFormat = new GTextFormat(FontUtil.xingkaiName, 24, 16711680, true, null, null, null, flash.text.TextFormatAlign.CENTER);
                this._wordTxt.filters = [FilterConst.nameGlowFilter];
                this._wordTxt.selectable = false;
                this._wordTxt.mouseEnabled = false;
                this._wordTxt.width = 1000;
                this._wordTxt.height = 100;
            }
            if (this._wordTxt.parent == null) 
            {
                LayerManager.windowLayer.addChild(this._wordTxt);
            }
            this.setText();
            this.stageResize();
            this.startTimer();
            return;
        }

        public hide(): void
        {
            if (this._wordTxt && !(this._wordTxt.parent == null)) 
            {
                LayerManager.windowLayer.removeChild(this._wordTxt);
            }
            this.stopTimer();
            return;
        }

        public stageResize(): void
        {
            if (this._wordTxt && this._wordTxt.parent) 
            {
                this._wordTxt.x = (Global.stage.stageWidth - this._wordTxt.textWidth) / 2;
                this._wordTxt.y = Global.stage.stageHeight / 2 - (Global.stage.stageHeight / 2 - this._wordTxt.textHeight) / 2;
            }
            return;
        }

        /* internal */ /* var */_wordTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_str: string;

        /* internal */ /* var */_daily: int;

        /* internal */ /* var */_count: int;

        /* internal */ /* var */_currentCount: int;

        /* internal */ /* var */_callBack: Function;

        /* internal */ /* var */_timer: SecTimer;
    }
